package com.mall.mapper;

import com.mall.domain.po.OrderItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @description: 订单详情持久层接口
 * @author 勾新杰
 * @version 1.0
 * @date 2024/11/25 11:38
 */
@Mapper
public interface OrderItemMapper {

    /**
     * 新增订单详情
     * @param orderItem 订单详情
     */
    @Insert("insert into order_item (order_id, item_id, quantity, price, subtotal, create_time, update_time) " +
            "values (#{orderId}, #{itemId}, #{quantity}, #{price}, #{subtotal}, #{createTime}, #{updateTime});")
    void insert(OrderItem orderItem);

    /**
     * 根据订单id查询订单详情
     * @param orderId 订单id
     * @return 订单详情列表
     */
    @Select("select id, order_id, item_id, quantity, price, subtotal, create_time, update_time from order_item where order_id = #{orderId};")
    List<OrderItem> getByOrderId(Long orderId);
}
